package com.cn.wanxi.front;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.ProductModel;
import com.cn.wanxi.service.ProductService;
import com.cn.wanxi.service.impl.ProductServiceImpl;
import com.cn.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet("/product")
public class ProductServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Map map = CommonServlet.getData();//公司信息和导航信息

        String page=req.getParameter("page");
        String limit=req.getParameter("limit");
        String whereShow = req.getParameter("whereShow");
        String cuisineId=req.getParameter("cuisineId");

        ProductModel productModel=new ProductModel();
        productModel.setPage(Tool.pageToInt(page));
        productModel.setLimit(Tool.limitToInt(limit));
        productModel.setWhereShow(Tool.stringToInt(whereShow));
        productModel.setCuisineId(Tool.stringToInt(cuisineId));

        ProductService productService=new ProductServiceImpl();
        List<ProductModel> productModelList=productService.getProductModelList(productModel);
        map.put("productModelList", productModelList);

        resp.getWriter().println(JSONObject.toJSONString(map));
    }
}
